package nl.weeaboo.sh.objects;

import javax.media.opengl.GL;

import nl.weeaboo.game.gl.GLManager;
import nl.weeaboo.game.input.UserInput;
import nl.weeaboo.sh.Game;
import nl.weeaboo.sh.level.Level;
import nl.weeaboo.sh.view.CharaImage;

public class Explosion extends Effect {

	private CharaImage image;
	private int x, y;
	private double rotation;
	private boolean mirror;	
	private boolean foreground;
	
	private int frame;
	private int maxFrame = 15;
	
	public Explosion(Game game, Level level, CharaImage image,
			int x, int y, double rotation, boolean mirror, boolean fg)
	{
		super(game, level);
		
		this.image = image;
		this.x = x;
		this.y = y;
		this.rotation = rotation;
		this.mirror = mirror;
		this.foreground = fg;
	}
	
	//Functions
	public void update(UserInput input, float dt) {
		frame++;
		if (frame > maxFrame) destroy();
	}
	public void drawBackground(GLManager glm) {
		if (!foreground) drawExplosion(glm);
	}
	public void drawForeground(GLManager glm) {		
		if (foreground) drawExplosion(glm);
	}
	
	protected void drawExplosion(GLManager glm) {
		GL gl = glm.getGL();
		gl.glPushMatrix();
		//gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
		glm.pushColor();
		
		gl.glTranslated(x, y, 0);		
		gl.glRotated(rotation, 0, 0, -1);

		//float c = 1.0f - Math.min(0.5f, (maxFrame-frame) / (float)(maxFrame / 2));
		float c = 1f;
		float a = (maxFrame-frame) / (float)maxFrame;
		glm.setColor(c, c, c, a);				
		image.draw(glm, mirror);				
		
		glm.popColor();
		gl.glPopMatrix();
		
		//gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);		
	}

	//Getters
	
	//Setters
	
}
